<?php defined('SYSPATH') or die('No direct script access.');
 
class Model_Country extends Model {

    public function countries($from = 0, $to = 30) {
        $sql = "select * from country order by name limit $from, $to";
        return DB::query(Database::SELECT, $sql)->execute()->as_array();
    }

    public function cities($id, $from = 0, $to = 30) {
        $sql = "select * from city where country_id=$id order by name limit $from, $to";
        return DB::query(Database::SELECT, $sql)->execute()->as_array();
    }

    public function countCountries() {
        $sql = "select count(country_id) from country";
        return DB::query(Database::SELECT, $sql)->execute()->as_array();
    }

    public function countCities($id) {
        $sql = "select count(city_id) from city where country_id=$id";
        return DB::query(Database::SELECT, $sql)->execute()->as_array();
    }


}